package com.gitee.feizns.quickstart.web.decrypt;

import com.gitee.feizns.quickstart.spring.AppUtils;
import lombok.NoArgsConstructor;

/**
 * {@link DecryptParameterResolver}和{@link DecryptServletModelAttributeMethodProcessor}中将解密过程进行开发，用于自定义解密规则
 * @see Decrypt
 * @see DecryptParameterResolver
 * @see DecryptServletModelAttributeMethodProcessor
 * @author feizns
 * @since 2019/7/26
 */
public interface DecryptionAlgorithm {

    /**
     * 加解密实例
     * @return {@link DecryptionAlgorithm }
     */
    static DecryptionAlgorithm instance() {
        return AppUtils.getBean(DecryptionAlgorithm.class);
    }

    /**
     * 自定义解密算法
     * @param original 前端传入的已加密字符
     * @return 解密后的字符
     */
    String decrypt(String original);

    /**
     * 解密失败
     */
    @NoArgsConstructor
    class DecryptionFailedException extends RuntimeException {
        public DecryptionFailedException(Throwable cause) {
            super(cause);
        }
    }

}

